﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Content;
using RebellionII.GameObjects.Other;
using RebellionII.GameObjects.Units;


namespace RebellionII.GameObjects
{
    [Flags]
    public enum TeamName
    {
        Empire,
        Alliance,
        Hutts,
        Smugglers,
        Default
    };

    public class Team
    {
        [ContentSerializer]
        public TeamName eName;

        #region UnitTypes For Team
        [ContentSerializer]
        public Dictionary<int, CapitalShip> lCapShips;

        [ContentSerializer]
        public Dictionary<int, Fighter> lFighters;

        [ContentSerializer]
        public Dictionary<int, Facility> lFacilities;

        [ContentSerializer]
        public Dictionary<int, Troop> lTroops;

        [ContentSerializer]
        public Dictionary<int, Character> lCharacters;

        [ContentSerializer]
        public Dictionary<int, Research> lResearch;

        [ContentSerializer]
        public Dictionary<int, Mission> lMissions;
        #endregion


        public Team()
        {
            lMissions = new Dictionary<int, Mission>();
            lFacilities = new Dictionary<int,Facility>();
            lResearch = new Dictionary<int, Research>();
            lFighters = new Dictionary<int, Fighter>();
            lCharacters = new Dictionary<int, Character>();
            lCapShips = new Dictionary<int, CapitalShip>();
            lTroops = new Dictionary<int, Troop>();
       }

        public void Initialize()
        {
            if (lMissions == null)
                lMissions = new Dictionary<int, Mission>();

            if (lResearch == null)
                lResearch = new Dictionary<int, Research>();

            if (lTroops == null)
                lTroops = new Dictionary<int, Troop>();

            if (lCapShips == null)
                lCapShips = new Dictionary<int, CapitalShip>();

            if (lCharacters == null)
                lCharacters = new Dictionary<int, Character>();

            if (lFacilities == null)
                lFacilities = new Dictionary<int, Facility>();

            if (lFighters == null)
                lFighters = new Dictionary<int, Fighter>();
            
        }

        public void LoadContent(string temp)
        {

        }

        public void Clear()
        {
            if(lMissions != null)
                lMissions.Clear();

            if (lResearch != null)
                lResearch.Clear();

            if (lTroops != null)
                lTroops.Clear();

            if (lCapShips != null)
                lCapShips.Clear();

            if (lCharacters != null)
                lCharacters.Clear();

            if (lFacilities != null)
                lFacilities.Clear();

            if (lFighters != null)
                lFighters.Clear();
        }

        /// <summary>
        /// Used to Load a Whole team into a single directory using their baseunits
        /// </summary>
        /// <returns>Dictionary of All Units</returns>
        public Dictionary<int, BaseUnit> ConvertToDictionary()
        {
            Dictionary<int, BaseUnit> tempDictionary = new Dictionary<int, BaseUnit>();

            foreach (var temp in lCharacters)
            {
                tempDictionary.Add(temp.Key, temp.Value);
            }
            foreach (var temp in lFighters)
            {
                tempDictionary.Add(temp.Key, temp.Value);
            }
            foreach (var temp in lFacilities)
            {
                tempDictionary.Add(temp.Key, temp.Value);
            }
            foreach (var temp in lTroops)
            {
                tempDictionary.Add(temp.Key, temp.Value);
            }
            foreach (var temp in lCapShips)
            {
                tempDictionary.Add(temp.Key, temp.Value);
            }

            return tempDictionary;
        }

        
    }
}
